 #pragma once
#include<iostream>
#include<unistd.h>
#include<functional>
#include<string>
#include<vector>
//对任务先描述再组织
class Task
{
    int _taskCode;
    std::function<void()> _function;
public:
    Task(int code,std::function<void()> f)
    :_taskCode(code)
    ,_function(f){}

    void RunTask()
    {
        _function();
    }
};

void Download()
{
    std::cout << "This is a Download Task" << " 处理者 ： " << getpid() << std::endl;
}

void Printlog()
{
    std::cout << "This is a Printlog Task" << " 处理者 ： " << getpid() << std::endl;
}

void PushVideoStream()
{
    std::cout << "This is a PushVideoStream Task" << " 处理者 ： " << getpid() << std::endl;
}

std::vector<Task> tasks = {Task(0,Download),Task(1,Printlog),Task(2,PushVideoStream)};

int SelectTask()
{
    return rand() % tasks.size();
}
bool CheckCode(int code)
{
    return code < tasks.size() && code >= 0;
}
std::string GetTaskName(int code)
{
    switch(code)
    {
        case 0:
            return "Download";
        case 1:
            return "Printlog";
        case 2:
            return "PushVideoStream";
        default:
            return "Unknow";
    }
}